{dede:config.pagesize value="30"/}
<!DOCTYPE html>
<html>
<head>
	<meta charset="<?php echo $cfg_soft_lang; ?>">
	<meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1">
    <title>联动枚举管理</title>
    <link rel="stylesheet" href="../static/web/css/bootstrap.min.css">
    <link rel="stylesheet" href="../static/web/font/css/font-awesome.min.css">
    <link rel="stylesheet" href="../static/web/css/admin.css">
    <script src="../static/web/js/webajax.js"></script>
    <script src="../static/web/js/jquery.min.js"></script>
    <script src="../static/web/js/bootstrap.bundle.min.js"></script>
    <script src='js/main.js'></script>
    <script>
        var loadhtml = "<center><img src='../static/web/img/loadinglit.gif' style='padding:30px' /></center>";
        function updateItem(aid) {
            var upenumf = document.getElementById('upenumf');
            upenumf.ename.value = $DE('ename' + aid).value;
            upenumf.disorder.value = $DE('disorder' + aid).value;
            upenumf.aid.value = aid;
            upenumf.submit();
        }
        function GetSelType() {
            var selvalue = $DE('egroup1').options[$DE('egroup1').selectedIndex].value;
            return selvalue;
        }
        function AddType() {
            $DE('edsta').style.display = 'block';
            fetch('stepselect_main.php?action=addnew').then(resp=>{
                if (resp.ok) {
                    return resp.text()
                }
                throw new Error('系统错误，无法获取数据');
            }).then((d)=>{
                $DE('edsta').innerHTML = d;
            }).catch((error) => {
                $DE('edsta').innerHTML = errMsg;
            });
        }
        function AddEnum() {
            var id = GetSelType();
            if (id == 0) {
                ShowMsg("必须选择一个类别");
                return false;
            }
            fetch('stepselect_main.php?action=addenum&id=' + id).then(resp=>{
                if (resp.ok) {
                    return resp.text()
                }
                throw new Error('系统错误，无法获取数据');
            }).then((d)=>{
                $DE('edsta').innerHTML = d;
            }).catch((error) => {
                $DE('edsta').innerHTML = errMsg;
            });
            $DE('edsta').style.display = 'block';
        }
        function EditType() {
            var id = GetSelType();
            if (id == 0) {
                ShowMsg("必须选择一个类别");
                return false;
            }
            $DE('edsta').style.display = 'block';
            fetch('stepselect_main.php?action=edit&id=' + id).then(resp=>{
                if (resp.ok) {
                    return resp.text()
                }
                throw new Error('系统错误，无法获取数据');
            }).then((d)=>{
                $DE('edsta').innerHTML = d;
            }).catch((error) => {
                $DE('edsta').innerHTML = errMsg;
            });
        }
        function ViewType() {
            var id = GetSelType();
            if (id == 0) {
                ShowMsg("必须选择一个类别");
                return false;
            }
            $DE('edsta').style.display = 'block';
            fetch('stepselect_main.php?action=view&id=' + id).then(resp=>{
                if (resp.ok) {
                    return resp.text()
                }
                throw new Error('系统错误，无法获取数据');
            }).then((d)=>{
                $DE('edsta').innerHTML = d;
            }).catch((error) => {
                $DE('edsta').innerHTML = errMsg;
            });
        }
        function DelType() {
            if (window.confirm("您确实要删除这个分类吗") == false) return false;
            var id = GetSelType();
            if (id == 0) {
                ShowMsg("必须选择一个类别");
                return false;
            }
            location.href = 'stepselect_main.php?action=del&id=' + id;
        }
        function CloseTWin() {
            $DE('edsta').innerHTML = loadhtml;
            $DE('edsta').style.display = 'none';
        }
        function ChangePage(sobj) {
            var ntxt = sobj.options[sobj.selectedIndex].text;
            if (sobj.options[sobj.selectedIndex].value == 0) {
                location.href = 'stepselect_main.php';
            } else {
                var ns = ntxt.split('|');
                location.href = 'stepselect_main.php?egroup=' + ns[0];
            }
        }
        function TogSel() {
            var ems = document.getElementsByName('ids[]');
            for (i = 0; i < ems.length; i++) {
                if (ems[i].checked == false) ems[i].checked = true;
                else ems[i].checked = false;
            }
        }
        function DelSel() {
            if (window.confirm("您确实要删除这些分类吗")) document.form1.submit();
        }
        function ChangePage2(sobj) {
            var nv = sobj.options[sobj.selectedIndex].value;
            if (sobj.options[sobj.selectedIndex].value == 0) {
                location.href = 'stepselect_main.php?egroup=<?php echo $egroup; ?>';
            } else {
                location.href = 'stepselect_main.php?egroup=<?php echo $egroup; ?>&topvalue=' + nv;
            }
        }
    </script>
    <style>
li{float:left;padding-right:10px;line-height:26px}
.abt{width:90%;border:1px #ffffff solid}
#edsta{position:absolute;top:70px;left:110px;width:280px;height:200px;background:#f8f8f8;border:1px solid #dedede;display:none;padding:6px}
#edsta div{margin:6px}
    </style>
</head>
<body>
    <div id="edsta">
        <center><img src="../static/web/img/loadinglit.gif"></center>
    </div>
    <table width="98%" align="center" cellpadding="3" cellspacing="1" class="table maintable mt-3 mb-3">
        <tr>
            <td height="26" background="../static/web/img/wbg.gif" colspan="6" style="padding-left:10px">联动枚举组管理</td>
        </tr>
        <tr>
            <td width="90">请选择组别：</td>
            <td width="260">
                <select name="egroup1" id="egroup1" onChange="ChangePage(this)" style="width:90%">
                    <option value='0'>所有组</option>
                    <?php
                    $selgroup = '';
                    foreach($etypes as $arr)
                    {
                        $stylecolor = "";
                        if($arr['issystem']==1) $stylecolor = " style='color:#999999' ";
                        if($egroup==$arr['egroup']) {
                            $selgroup = $arr['itemname'];
                            echo "<option value='{$arr['id']}' $stylecolor selected='1'>{$arr['egroup']}|{$arr['itemname']}</option>";
                        } else {
                            echo "<option value='{$arr['id']}' $stylecolor>{$arr['egroup']}|{$arr['itemname']}</option>";
                        }
                    }
                    ?>
                </select>
            </td>
            <td colspan="2"><i class="fa fa-question-circle" title="帮助"></i> 灰色字的为系统内置枚举，您是不能对它进行删除修改操作的，但可以添加或修改它的元素</td>
            <td>
                <button type="button" name="gedit" id="gedit" class="btn btn-success btn-sm" onClick="EditType()">修改</button>
                <button type="button" name="gdel" id="gdel" class="btn btn-success btn-sm" onClick="DelType()">删除</button>
                <button type="button" name="gview" id="gview" class="btn btn-success btn-sm" onClick="ViewType()">预览</button>
            </td>
            <td>
                <button type="button" name="addnew" id="addnew" class="btn btn-success btn-sm" onClick="AddType()">新增类别组</button>
                <a href='stepselect_main.php?action=upallcache' class="btn btn-success btn-sm">更新所有枚举缓存</a>
            </td>
        </tr>
    </table>
    <?php
    if(!empty($egroup))
    {
        $arr = $dsql->GetOne("SELECT * FROM `#@__stepselect` WHERE egroup='{$egroup}' ");
        $dsql->Execute('out',"SELECT evalue,ename FROM `#@__sys_enum` WHERE egroup='{$arr['egroup']}' ORDER BY disorder ASC,evalue ASC");
        $options = '';
        while($row1 = $dsql->GetArray('out'))
        {
            if(!preg_match("#\.#", $row1['evalue']))
            {
                $row1['ename'] = ($row1['evalue'] % 500 == 0)? $row1['ename'] : '└─'.$row1['ename'];
                if($topvalue != $row1['evalue']) $options .= "<option value='{$row1['evalue']}'>{$row1['ename']}</option>";
                else $options .= "<option value='{$row1['evalue']}' selected='selected'>{$row1['ename']}</option>";
            }
        }
        //如果添加3级之类
        if($topvalue % 500 != 0) $arr['issign'] = 2;
    ?>
    <table width="98%" cellpadding="3" cellspacing="1" align="center" class="table maintable mb-3">
        <tr>
            <td height="26" background="../static/web/img/tbg.gif" colspan="8">
                <div style="float:left"><?php echo $selgroup; ?> &gt; 子分类管理</div>
                <div style="float:right">
                <?php
                if($egroup=='nativeplace') {
                    echo "<a href='stepselect_main.php?action=exarea' class='np coolbg'>把默认省市地区表导入</a>";
                }
                ?>
                </div>
            </td>
        </tr>
        <tr>
            <td>
                <form action='stepselect_main.php' method='post'>
                    <input type="hidden" name="action" value="addenum_save">
                    <input type="hidden" name="issign" value="<?php echo $arr['issign']; ?>">
                    <input type="hidden" name="egroup" value="<?php echo $arr['egroup']; ?>">
                    <div style="float:left">
                        隶属分类：
                        <select name="topvalue" style='width:160px' onChange="ChangePage2(this)">
                            <option value="0"><?php echo $selgroup; ?></option>
                            <?php echo $options; ?>
                        </select>
                    </div>
                    <div style="float:left">分类名称：<input type="text" name="ename" class="iptxt" style="width:260px"></div>
                    <div style="float:left;padding-left:10px">
                        <button type="submit" name="sb2" class="btn btn-success btn-sm">增加分类</button>
                    </div>
                    <div style="clear:both"><i class="fa fa-question-circle" title="帮助"></i> 如果没选择隶属分类则表示增加的是顶级分类，用半角逗号","分开可以一次增加多个分类</div>
                </form>
            </td>
        </tr>
    </table>
    <table width="98%" align="center" cellpadding="3" cellspacing="1" class="table maintable">
        <tr>
            <td height="26" background="../static/web/img/tbg.gif" colspan="8">
                <div style="float:left">
                    <a href="stepselect_main.php">枚举组列表</a>
                    &gt; <a href="stepselect_main.php?egroup=<?php echo $egroup; ?>"><?php echo $selgroup; ?></a>
                    &gt; 子分类列表
                </div>
                <div style="float:right"></div>
            </td>
        </tr>
        <tr align="center" bgcolor="#F8FCF1" height="26">
            <td width="6%">选择</td>
            <td width="6%">编号</td>
            <td width="20%">枚举名</td>
            <td width="20%">类别组名</td>
            <td width="10%">枚举类型</td>
            <td width="10%">枚举值</td>
            <td width="10%">组内排序</td>
            <td width="18%">操作</td>
        </tr>
        <form action='stepselect_main.php' name='upenumf' method='post' id="upenumf">
            <input type='hidden' name='action' value='upenum' />
            <input type="hidden" name="aid" value="">
            <input type='hidden' name='ename' value='' />
            <input type='hidden' name='disorder' value='' />
        </form>
        <form name='form1' action='stepselect_main.php' method='post'>
            <input type='hidden' name='action' value='delenumAllSel' />
            {dede:datalist empty='<tr><td colspan="8"><center>暂无内容</center></td></tr>'}
            <tr height="26" align="center" onMouseMove="javascript:this.bgColor='#F8FCF1';" onMouseOut="javascript:this.bgColor='#FFFFFF';">
                <td><input type='checkbox' name='ids[]' value='{dede:field.id /}' class='np' /></td>
                <td>{dede:field.id /}</td>
                <td>
                <?php 
                if(!preg_match("#\.#", $fields['evalue']))
                {
                    if($fields['evalue']>500 && $fields['evalue']%500 != 0)  $fields['ename'] = " └─".$fields['ename'];
                } else {
                    $fields['ename'] = " └───".$fields['ename'];
                }
                ?>
                <input type='text' id='ename{dede:field.id/}' value='{dede:field.ename /}' class='abt' />
                </td>
                <td>{dede:field.egroup /}</td>
                <td>
                <?php
                if(!preg_match("#\.#", $fields['evalue']))
                {
                    if($fields['evalue']>500 && $fields['evalue']%500 != 0)  echo '二级选择';
                    else echo '一级选择';
                } else {
                    echo "三级选择";
                }
                ?></td>
                <td>{dede:field.evalue /}</td>
                <td><input type='text' id='disorder{dede:field.id/}' value='{dede:field.disorder /}' class='abt' /></td>
                <td>
                <?php
                if(!empty($egroup))
                {
                ?>
                    <a href='javascript:updateItem({dede:field.id/});' class="btn btn-success btn-sm"> <i class="fa fa-refresh"></i> 更新</a>
                    <a href='stepselect_main.php?action=delenum&id={dede:field.id/}' class="btn btn-success btn-sm"> <i class="fa fa-trash"></i> 删除</a>
                    <?php
                } else {
                    echo "<a href='stepselect_main.php?egroup={$fields['egroup']}'>".$egroups[$fields['egroup']]."</a>";
                }
                ?>
                </td>
            </tr>
            {/dede:datalist}
        </form>
        <tr height="26">
            <td colspan="8">
                <a href="javascript:TogSel();" class="btn btn-success btn-sm">全选/反选</a>
                <a href="javascript:DelSel();" class="btn btn-success btn-sm">删除所选</a>
            </td>
        </tr>
        <tr height="26" bgcolor="#f8f8f8" align="center">
            <td colspan="8">{dede:pagelist listsize=6/}</td>
        </tr>
    </table>
    <?php
    } else {
    ?>
    <table width="98%" cellpadding="3" cellspacing="1" align="center" class="table maintable mb-3">
        <tr>
            <td height="26" background="../static/web/img/tbg.gif" colspan="8">
                <div style="float:left">
                    <a href="stepselect_main.php">枚举组列表</a>
                </div>
                <div style="float:right"></div>
            </td>
        </tr>
        <tr height="26" bgcolor="#F8FCF1" align="center">
            <td width="6%">选择</td>
            <td width="6%">编号</td>
            <td width="28%">组类别名</td>
            <td width="10%">级数</td>
            <td width="10%">系统</td>
            <td width="15%">缓存组名</td>
            <td>操作</td>
        </tr>
        {dede:datalist}
        <tr height="26" align="center" onMouseMove="javascript:this.bgColor='#F8FCF1';" onMouseOut="javascript:this.bgColor='#FFFFFF';">
            <td><input type='checkbox' name='ids[]' value='{dede:field.id /}' class='np' /></td>
            <td> {dede:field.id /} </td>
            <td> <a href="stepselect_main.php?egroup={dede:field.egroup /}">{dede:field.itemname /}</a></td>
            <td>
                <?php
                switch ($fields['issign']) {
                    case 0:
                        echo "一级选择";
                        break;
                    case 1:
                        echo "二级选择";
                        break;
                    case 2:
                        echo "三级选择";
                        break;
                }
                ?>
            </td>
            <td> {dede:field.issystem function="@me==1 ? '是' : '否'" /} </td>
            <td>{dede:field.egroup /}</td>
            <td>
                <a href="stepselect_main.php?action=upallcache&egroup={dede:field.egroup/}" class="btn btn-success btn-sm"><i class="fa fa-refresh"></i> 更新缓存</a>
                <a href="stepselect_main.php?egroup={dede:field.egroup/}" class="btn btn-success btn-sm"><i class="fa fa-list-ul"></i> 查看子分类</a>
            </td>
        </tr>
        {/dede:datalist}
        <tr height="26" align="center" bgcolor="#f8f8f8">
            <td colspan="8">{dede:pagelist listsize=6/}</td>
        </tr>
    </table>
    <?php
    }
    ?>
</body>
</html>